from app.models import IndustryInformation
from app import db
from exts import JsonConverter, BeanUtils


def industry_information_add(industry_information):
    '''
    添加资讯
    :param industry_information:
    :return:
    '''
    o = JsonConverter.dict_to_object(industry_information, IndustryInformation)
    db.session.add(o)
    db.session.commit()


def industry_information_update(industry_information):
    '''
    更新资讯
    :param industry_information:
    :return:
    '''
    '''
    :param news:
    :return:
    '''
    o = IndustryInformation.query.get(industry_information['id'])
    # 对象复制
    BeanUtils.copy(industry_information, o)
    db.session.commit()


def industry_information_delete(id):
    '''
    删除资讯
    :param id:
    :return:
    '''
    o = IndustryInformation.query.get(id)
    db.session.delete(o)
    db.session.commit()


def industry_information_detail(id):
    '''
    查询资讯详情
    :param id:
    :return:
    '''
    return IndustryInformation.query.get(id)


def industry_information_get_by_id(id):
    '''
    查询资讯详情
    :param id:
    :return:
    '''
    return IndustryInformation.query.get(id)


def industry_information_page(pageNum, pageSize):
    '''
    分页查询资讯
    :param params:
    :return:
    '''
    return IndustryInformation.query.paginate(page=pageNum, per_page=pageSize)


def industry_information_all():
    '''
    查询所有资讯
    :return:
    '''
    return IndustryInformation.query.all()
